﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model;
using System.Data;
using HZ.DrugTrade.Model.Enum;

namespace HZ.DrugTrade.Web.Admin.RelationQuery
{
    public partial class RelationShipDelLogDetail : BasePage
    {
        public RelationShipDelLogDetail()
        {
            this.ModuleNo = Module.查看不良记录.ToString();
        }


        IBLL_AreaDistributionDelLog ih = Factory.BLL_AreaDistributionDelLog();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SetBind();
            }
        }

        /// <summary>
        /// 绑定符合条件的采购明细
        /// </summary>
        private void SetBind()
        {
            int totalCount;
            IList<Model.View.AreaDistributionDelLog> purchaseOrderDetailList = ih.GetAreaDistributionDelLogByProcureCatalogID(GetQuery(), AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            AspNetPager1.RecordCount = totalCount;
            GvRelaion.PageSize = AspNetPager1.PageSize;
            GvRelaion.DataSource = purchaseOrderDetailList;
            GvRelaion.DataBind();
        }
        public Model.Query.AreaDistributionDelLog GetQuery()
        {

            Model.Query.AreaDistributionDelLog where = new HZ.DrugTrade.Model.Query.AreaDistributionDelLog();
            //if (string.IsNullOrEmpty(Request["AreaID"]) || string.IsNullOrEmpty(Request["CompanyID_PS"]) || string.IsNullOrEmpty(Request["CompanyID_TB"]))
            //   PageError("系统参数错误", this.ReturnUrl);

            if (CurrentAccount.GetUser().UserRole.RoleID == "02") //配送企业
            {
                where.CompanyID_PS = CurrentAccount.GetUser().Org.OrgName;
                where.CompanyID_TB = Request["CompanyID_TB"];
            }
            else if (CurrentAccount.GetUser().UserRole.RoleID == "05")// 生产企业
            {
                where.CompanyID_TB = CurrentAccount.GetUser().Org.OrgName;
                where.CompanyID_PS = Request["CompanyID_PS"];
            }
            else
            {
                where.CompanyID_TB = Request["CompanyID_TB"];
                where.CompanyID_PS = Request["CompanyID_PS"];
            }
            if (!string.IsNullOrEmpty(Request["AreaID"]))
            {
                where.Append = string.Format("Areaid='{0}' ", Request["AreaID"]);
            }
            //  where.AreaID = Request["AreaID"];
            where.GoodsID = txtGoodsID.Text.Trim();//产品编号
            where.GoodsName = txtGoodsName.Text.Trim();//产品名称
            where.Material = txtMaterial.Text.Trim();//材质
            where.Outlookc = txtOutlookc.Text.Trim();

            where.SortFields = " AreaID ";
            return where;
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;

            SetBind();
        }

        /// <summary>
        /// 翻页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            SetBind();
        }


        /// <summary>
        /// 导出2009-11-25
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExport_Click(object sender, EventArgs e)
        {

            int totalCount = 0;
            IList<Model.View.AreaDistributionDelLog> purchaseOrderDetailList = ih.GetAreaDistributionDelLogByProcureCatalogID(GetQuery(), 1, 0, out totalCount);
            System.Data.DataTable tb = HZ.Data.ModelConvert.GetDataTableFromModel(purchaseOrderDetailList);
            HZ.Excel.ExcelHelper.ExportDataForWeb(tb, GvRelaion);

        }

    }
}
